package com.xing.controller;

import com.xing.Utils.Result;
import com.xing.dto.LiveRoomUpdateDTO;
import com.xing.dto.LiveTagDTO;
import com.xing.dto.LiveTagSaveDTO;
import com.xing.dto.LiveTagUpdateDTO;
import com.xing.service.LiveTagService;
import com.xing.utils.PageData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "系统标签管理")
@RestController
@RequestMapping(value = "/liveTag")
public class LiveTagController {

    @Autowired
    private LiveTagService liveTagService;

    @Operation(summary = "分页查询系统标签")
    @GetMapping(value = "/getSystemTagByPage")
    @PreAuthorize("hasAnyAuthority('admin','live')")
    public Result getSystemTagByPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        PageData<LiveTagDTO> liveTagDtoPage = liveTagService.getSystemTagByPage(pageNum, pageSize);
        return new Result().ok(liveTagDtoPage);
    }


    @Operation(summary = "根据名称查询标签")
    @GetMapping(value = "/getSystemTagByName")
    @PreAuthorize("hasAnyAuthority('admin','live')")
    public Result getSystemTagByName(@RequestParam String name) {
        List<LiveTagDTO> liveTagDtoList = liveTagService.getSystemTagByName(name);
        return new Result().ok(liveTagDtoList);
    }


    @Operation(summary = "新增系统标签")
    @PostMapping(value = "/saveSystemTag")
    @PreAuthorize("hasAnyAuthority('admin')")
    public Result saveSystemTag(@RequestBody LiveTagSaveDTO liveTagSaveDTO) {
        return liveTagService.saveSystemTag(liveTagSaveDTO);
    }


    @Operation(summary = "修改系统标签")
    @PutMapping(value = "/updateSystemTag")
    @PreAuthorize("hasAnyAuthority('admin')")
    public Result updateSystemTag(@RequestBody LiveTagUpdateDTO liveTagUpdateDTO) {
        return liveTagService.updateSystemTag(liveTagUpdateDTO);
    }


    @Operation(summary = "删除系统标签")
    @DeleteMapping(value = "/deleteSystemTag")
    @PreAuthorize("hasAnyAuthority('admin')")
    public Result deleteSystemTag(@RequestParam Long id) {
        return liveTagService.deleteSystemTag(id);
    }


}
